Calculate current Date of Birth

An example sequence of @commands is given below, which could be used to calculate the age of the person in whole years and days, and the date of a person's last birthday, relative to the current system date. You could Copy this example from within the Windows help topic and paste it (using CTRL+V) into a command window of your own application, making any editing changes to better suit your needs. Error trapping must be added if required.

Three date attributes are needed in this example:

System_Date, Date_of_Birth and Last_Birthday.

The input DOB is expected in Date_of_Birth. The calculated age result is then stored in Age_Years and Age_Days, with a calculated last birthday stored in Last_Birthday.

The use of the DecodeDate command and the EncodeDate FUNCTION allows for different country settings of system dates.

@Date System_Date
@DecodeDate Date_of_Birth,DOB_Day, DOB_Month, DOB_Year
@DecodeDate System_Date, System_Day, System_Month, System_Year 
@Assign Age_Years = System_Year - DOB_Year
@If EncodeDate(DOB_Day, DOB_Month,1900) > EncodeDate(System_Day, System_Month,1900)
@Assign Age_Years = Age_Years - 1
@Assign Last_Birthday = EncodeDate(DOB_Day, DOB_Month, System_Year - 1)
@Else
@Assign Last_Birthday = EncodeDate(DOB_Day, DOB_Month, System_Year)
@EndIf
@Assign Age_Days = System_Date - Last_Birthday